//spu管理模块接口
import request from '../../../utils/request'
//引入ts类型
import type {
  SpuResponseData,
  AllTrademarkResponseData,
  SpuImageResponseData,
  SaleAttrResponseData,
  HasSaleAttrResponseData,
  SpuData,
} from './type'

enum API {
  //获取spu列表接口
  SpuList_URL = '/admin/product',
  //获取全部品牌接口
  All_TRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
  //获取 spuId 图片列表
  SpuImageList_URL = '/admin/product/spuImageList',
  //指定 spuId 的销售属性
  SpuSaleAttrList_URL = '/admin/product/spuSaleAttrList/',
  //获取整个项目全部的销售属性
  All_SaleAttr_URL = '/admin/product/baseSaleAttrList',
  //添加一个新的SPU
  AddSPU_URL = '/admin/product/saveSpuInfo',
  //更新SPU
  UpdateSPU_URL = '/admin/product/updateSpuInfo',
}
//获取某一个某一个三级分类下已有的spu数据
export const reqHasSpu = (page: number, limit: number, category3Id: number) =>
  request.get<any, SpuResponseData>(
    API.SpuList_URL + `/${page}/${limit}?category3Id=${category3Id}`,
  )
//获取全部的SPU品牌数据
export const reqAllTradeMark = () =>
  request.get<any, AllTrademarkResponseData>(API.All_TRADEMARK_URL)
//获取 spuId 图片列表
export const reqSpuImageList = (spuId: number) =>
  request.get<any, SpuImageResponseData>(API.SpuImageList_URL + `/${spuId}`)
//指定 spuId 的销售属性
export const reqSpuSaleAttrList = (spuId: number) =>
  request.get<any, SaleAttrResponseData>(API.SpuSaleAttrList_URL + `${spuId}`)
//获取整个项目全部的销售属性
export const reqAllSaleAttr = () =>
  request.get<any, HasSaleAttrResponseData>(API.SpuSaleAttrList_URL)
//添加或更新SPU
export const reqAddOrUpdateSpu = (data: SpuData) => {
  if (data.id) {
    return request.post<any, any>(API.UpdateSPU_URL, data)
  } else {
    return request.post<any, any>(API.AddSPU_URL, data)
  }
}
